//
//  PartyTableViewCell.m
//  OneDay
//
//  Created by lanou3g on 15/10/27.
//  Copyright © 2015年 oneDay. All rights reserved.
//

#import "PartyTableViewCell.h"


@implementation PartyTableViewCell

// 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubViews];
        self.contentView.backgroundColor = [UIColor colorWithRed:205.91 / 255.0 green:239.77 / 255.0 blue:214.26 / 255.0 alpha:1];
    }
    return self;
}
// 自定义Cell
- (void)addSubViews
{
    CGFloat kh = 0.85 * kWidth;
    CGFloat kSpace = 0.02 * kWidth;
    // 首页图片
    self.cover_image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 0.65 * kh)];
    [self.contentView addSubview:self.cover_image];
    
    // 首页标题
    self.partyTitle = [[UILabel alloc] initWithFrame:CGRectMake(kSpace, self.cover_image.bottom + kSpace / 2, kWidth - 2 * kSpace, 0.15 * kh)];
    self.partyTitle.font = [UIFont systemFontOfSize:18];
    self.partyTitle.numberOfLines = 0;
    [self.contentView addSubview:self.partyTitle];
    
    // 活动举办方
    self.activit_name = [[UILabel alloc] initWithFrame:CGRectMake(kSpace, self.partyTitle.bottom + kSpace / 2, kWidth - 2 * kSpace, 0.1 * kh)];
    self.activit_name.font = [UIFont systemFontOfSize:14];
    self.activit_name.numberOfLines = 0;
    [self.contentView addSubview:self.activit_name];
    
    // 活动时间
    self.party_time = [[UILabel alloc] initWithFrame:CGRectMake(kSpace, self.activit_name.bottom + kSpace / 2, 0.4 * kWidth, 0.06 * kh)];
    self.party_time.font = [UIFont systemFontOfSize:14];
    self.party_time.layer.borderWidth = 0.5;
    self.party_time.layer.cornerRadius = self.party_time.frame.size.width / 25;
    [self.contentView addSubview:self.party_time];
    
    // 收藏人数
    self.collectedNum = [[UIButton alloc] initWithFrame:CGRectMake(self.party_time.right + kSpace, self.activit_name.bottom + kSpace / 2, 0.2 * kWidth, 0.06 * kh)];
    self.collectedNum.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.collectedNum setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    //self.collectedNum.font = [UIFont systemFontOfSize:14];
    self.collectedNum.layer.borderWidth = 0.5;
    self.collectedNum.layer.cornerRadius = self.collectedNum.frame.size.width / 25;
    [self.contentView addSubview:self.collectedNum];
    
    // 价格
    self.party_price = [[UILabel alloc] initWithFrame:CGRectMake(0.8 * kWidth, self.activit_name.bottom + kSpace / 2, 0.17 * kWidth, 0.06 * kh)];
    self.party_price.font = [UIFont systemFontOfSize:14];
    self.party_price.layer.borderWidth = 0.5;
    self.party_price.layer.cornerRadius = self.party_price.frame.size.width / 20;
    [self.contentView addSubview:self.party_price];
    
    
}

#pragma mark -- 重写model方法
- (void)setModel:(PartyModel *)model
{
    if (_model != model) {
        _model = model;
    }
    // 赋值
    self.partyTitle.text = model.title;
    
    NSString *distance = [NSString stringWithFormat:@"%0.2fkm", (float)model.distance / 1000];
    if ([model.poi_name isEqualToString:@""]) {
        self.activit_name.text = [NSString stringWithFormat:@"%@ . %@", distance, model.category];
    }else{
        self.activit_name.text = [NSString stringWithFormat:@"%@ . %@ . %@", model.poi_name, distance, model.category];
    }
    
    OneDayObject *oneObject = [[OneDayObject alloc] init];
    CGFloat kh = 0.85 * kWidth;
    CGFloat kSpace = 0.02 * kWidth;
    
    CGRect timeFrame = self.party_time.frame;
    timeFrame.size.width = [oneObject sizeWithText:model.time_info font:14 width:1000 height:0.06 * kh].width;
    self.party_time.frame = timeFrame;
    self.party_time.text = model.time_info;
    
    CGRect collectFrame =  self.collectedNum.frame;
    collectFrame.origin.x = self.party_time.right + kSpace;
    self.collectedNum.frame = collectFrame;
    [self.collectedNum setTitle:[NSString stringWithFormat:@"%ld收藏", model.collected_num] forState:(UIControlStateNormal)];
    
    if (model.price == 0) {
        self.party_price.text = @"免费";
    }else{
        self.party_price.text = [NSString stringWithFormat:@"￥%ld", model.price];
    }
    
    NSArray *array = model.front_cover_image_list;
    [self.cover_image sd_setImageWithURL:[NSURL URLWithString:array[0]] placeholderImage:[UIImage imageNamed:@"oneDay.jpg"]];
    
    
}






@end
